﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Windows.Forms;
using CommonLibrary.DBUtility;
using Microsoft.Win32;
using Yipusoft.SystemSet;

namespace SmsSeries
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            RegistryKey hkml = Registry.LocalMachine;
            RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
            hkml = Registry.LocalMachine;
            software = hkml.OpenSubKey("SOFTWARE", true);
            RegistryKey command = software.OpenSubKey("Yipusoft\\SmsSeries", true);
            if (command == null)
            {
                frmSetup frmSetup1 = new frmSetup();
                Application.Run(frmSetup1);
            }
            else
            {
                //连接数据库
                string SQLServer = Func.GetItem("Yipusoft\\SmsSeries", "SQLServerName");
                string SQLUserName = Func.GetItem("Yipusoft\\SmsSeries", "SQLUserName");
                string SQLPassword = Func.GetItem("Yipusoft\\SmsSeries", "SQLPassword");

                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = string.Format("server={0}; uid={1}; pwd={2}; database=SmsSeries;"
                    ,SQLServer,SQLUserName,SQLPassword);

                bool isLoad = false; ;
                try
                {
                    conn.Open();
                    isLoad = true;
                }
                catch (SqlException)
                {
                    frmSetup frmSetup1 = new frmSetup();
                    Application.Run(frmSetup1);
                }

                if(isLoad)
                {
                    SqlHelper s = new SqlHelper(false);
                    Application.Run(new frmMain());
                }
            }
        }
    }
}
